﻿using System;
using System.Collections.Generic;
using System.Web.SessionState; 
using System.Linq;
using System.Web;
using System.Web.Services;
using HKEA.CMS.Core.BLL;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.BLL.Tbl;


namespace WebApplication
{
    /// <summary>
    /// AutoCompleteProcessor 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class AutoCompleteProcessor : System.Web.Services.WebService, IRequiresSessionState 
    {

        private static List<tblCustomer> CustList = null;
        [WebMethod]
        public string[] GetCustmerInfoList(string prefixText, int count)
        {
            if (count == 0)
            {
                count = 20;
            }

            if (CustList==null)
            {
                tblCustomerBLL bllCust = new tblCustomerBLL();
                tblCustomer entCust = new tblCustomer();
                CustList = new List<tblCustomer>();

                entCust.Deleted = 0;
                CustList = bllCust.GetListByENT(entCust);
            }


            List<string> items = new List<string>(count);
            int j = 0;
            foreach (tblCustomer ent in CustList)
            {
                if (ent.CustomerID.Contains(prefixText) || ent.Name_Eng.Contains(prefixText))
                {
                    if (j <= count)
                    {
                        items.Add(ent.CustomerID.Trim() + " & " + ent.Name_Eng.Trim());
                        j++;
                    }
                }
            }
            
            return items.ToArray();
        }

    }
}
